/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SourceCode;

/**
 *
 * @author ssaad
 */
import java.awt.GradientPaint;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class DataRange
{
    private Date Start;
    private Date End;
    Calendar calendar ;
     public DataRange()
     {
        Start = new Date();
        End = new Date();

     }
     

    public Date getEnd() {
        return End;
    }

    public Date getStart() {
        return Start;
    }

    public Calendar getCalendar() {
        return calendar;
    }

    public DataRange(Date start , Date end)
    {
        super();
        this.Start = start;
        this.End = end;
    }

    public DataRange(Date start , int Range)
    {
        super();
        this.Start = start;
        calendar = new GregorianCalendar();
        calendar.setTime(Start);
        calendar.add(Calendar.DAY_OF_MONTH , Range);
        this.End = calendar.getTime();

    }

    public boolean IsInRange(Date date)
    {
        if(Start.compareTo(date) <=0 && End.compareTo(date) >=0)
        {
            return true;
        }
        else
        {
            return  false;
        }
    }

    public int DayLimits(Date date)
    {
        int days=0;
        //cal;culate days if exist
        if(IsInRange(date) == false)
        {
            if(Start.compareTo(date) > 0)
            {
                days = getdifferencedates(Start , date);
            }
            else
            {
                days = getdifferencedates( date, End);
            }
        }

        return days;
    }

    public int getdifferencedates(Date date1 , Date date2)
    {
        int diff=0;
        long milPerDay = 1000*60*60*24;
        Calendar c1,c2;
        c1 = new GregorianCalendar();
        c2 = new GregorianCalendar();
        c1.setTime(date1);
        c2.setTime(date2);

        diff = (int)((c1.getTime().getTime() -  c2.getTime().getTime()) /milPerDay  ) +30;
        //diff = c1.get(Calendar.DATE) - c2.get(Calendar.DATE);
        return diff;
    }


}
